//
//  BaseADViewController.m
//  nanzhaodaili
//
//  Created by mac on 2018/2/7.
//  Copyright © 2018年 gzx. All rights reserved.
//

#import "BaseADViewController.h"
#import "MBProgressHUD.h"
#import "ZXNavigationViewController.h"

@interface BaseADViewController ()

@property (nonatomic,strong) MBProgressHUD *hud;

@end

@implementation BaseADViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    
    [UIActivityIndicatorView appearanceWhenContainedInInstancesOfClasses:@[[MBProgressHUD class]]].color = [UIColor whiteColor];
    self.view.backgroundColor = DEFAULT_BACKCOLOR;
    
    

}
-(UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}
- (void)AddLeftImageBtn:(UIImage *)image target:(id)target action:(SEL)action{
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    rightBtn.frame = CGRectMake(0, 0, 44, 44);
    [rightBtn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    rightBtn.adjustsImageWhenHighlighted = NO;
    rightBtn.imageEdgeInsets = UIEdgeInsetsMake(0,0,0,20);
    [rightBtn setImage:image forState:UIControlStateNormal];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:rightBtn];
}
- (void)AddRightImageBtn:(UIImage *)image target:(id)target action:(SEL)action{
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    rightBtn.frame = CGRectMake(0, 0, 44, 44);
    rightBtn.imageEdgeInsets = UIEdgeInsetsMake(0,20, 0,0);
    [rightBtn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    rightBtn.adjustsImageWhenHighlighted = NO;
    [rightBtn setImage:image forState:UIControlStateNormal];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:rightBtn];
}
- (void)AddRightTextBtn:(NSString *)name target:(id)target action:(SEL)action{
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [rightBtn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    rightBtn.adjustsImageWhenHighlighted = NO;
    [rightBtn setTitle:name forState:UIControlStateNormal];
    [rightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    rightBtn.titleLabel.font = [UIFont systemFontOfSize:16.];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:rightBtn];
}
- (void)AddLeftTextBtn:(NSString *)name target:(id)target action:(SEL)action{
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [rightBtn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    rightBtn.adjustsImageWhenHighlighted = NO;
    [rightBtn setTitle:name forState:UIControlStateNormal];
    [rightBtn setTitleColor:[UIColor colorWithWhite:0.2 alpha:1] forState:UIControlStateNormal];
    rightBtn.titleLabel.font = [UIFont systemFontOfSize:16.];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:rightBtn];
}
- (void)StartLoading{
    if (self.hud) {
        [self.hud removeFromSuperview];
    }
    self.hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    self.hud.mode = MBProgressHUDModeIndeterminate;
    self.hud.bezelView.color = [UIColor blackColor];
    self.hud.label.textColor = [UIColor whiteColor];
    [self.view addSubview:self.hud];
    [self.view bringSubviewToFront:self.hud];
    [_hud showAnimated:YES];
}
- (void)showMsg:(NSString *)msg{
    MBProgressHUD  *myLoadView = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [self.view addSubview:myLoadView];
    myLoadView.mode = MBProgressHUDModeText;
    myLoadView.label.text = msg;
    myLoadView.bezelView.color = [UIColor blackColor];
    myLoadView.label.textColor = [UIColor whiteColor];
    [myLoadView showAnimated:YES];
    [myLoadView hideAnimated:YES afterDelay:1];
    myLoadView = nil;
}
/**
 *  隐藏hud
 */
- (void)StopLoading{
    [_hud hideAnimated:YES];
}
-(void)GoBack{
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)dealloc{
    NSLog(@"页面释放");
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
